(function ($) {
    var Magiclamp = {
        /**
         * 禁止页面滚动
         * @returns {boolean}
         */
        noScroll: function (e) {
            e.preventDefault && e.preventDefault();
            e.returnValue = false;
            e.stopPropagation && e.stopPropagation();
            return false;
        },
        /**
         * 恢复页面滚动
         * @returns {boolean}
         */
        goScroll: function (e) {
            e.preventDefault && e.preventDefault();
            e.returnValue = true;
            e.stopPropagation && e.stopPropagation();
            return true;
        },
        /**
         * toast提示
         * @toastTxt string toast提示的文字内容（默认 “操作成功”）
         * @posBottom string toast最终定位位置（默认“6rem”）
         */
        mcToast: function (toastTxt, posBottom) {
            var toastTxt = (toastTxt === null || toastTxt === undefined || toastTxt === "") ? "操作成功" : toastTxt;
            var toastPos = (posBottom === null || posBottom === undefined || posBottom === "") ? "6rem" : posBottom;
            if ($("#toast").length === 0) {
                var timer;
                var toastHTml = "<div id=\"toast\">" +
                    toastTxt +
                    "</div>";
                $("body").append(toastHTml);
                $("#toast").animate({
                    bottom: toastPos
                }, 200, function () {
                    timer = setTimeout(function () {
                        $("#toast").animate({
                            bottom: "-4rem"
                        }, 200, function () {
                            $(this).remove();
                        })
                    }, 1500);
                })
            }
        },
        /**
         * 屏幕中间提示，用于反馈用户相对重要操作，（默认 "success"） 例 ，添加购物车成功
         * @param type 提示类型，两种：success，fail
         * @param toastTxt  提示文字 （默认 “操作成功”）
         * @param fn 隐藏提示后执行的函数
         */
        midToast: function (type, toastTxt, fn) {
            var toastType = (type === null || type === undefined || type === "") ? "success" : type;
            var toastTxt = (toastTxt === null || toastTxt === undefined || toastTxt === "") ? "操作成功" : toastTxt;
            var sucHtml =
                "<div id=\"mid-toast\">" +
                "        <p class=\"toast-icon\">" +
                "            <i class=\"iconfont icon-chenggong\"></i>" +
                "        </p>" +
                "        <p class=\"toast-txt\">" + toastTxt + "</p>" +
                "    </div>";
            var failHTml =
                "<div id=\"mid-toast\">" +
                "        <p class=\"toast-icon\">" +
                "            <i class=\"iconfont icon-shibai\"></i>" +
                "        </p>" +
                "        <p class=\"toast-txt\">" + toastTxt + "</p>" +
                "    </div>";
            var append = function (htmlCode) {
                $("body").append(htmlCode);
                $("#mid-toast").fadeIn().delay(800).fadeOut(200, function () {
                    $("#mid-toast").remove();
                    if (fn && typeof fn === "function") {
                        fn()
                    }
                });
            };
            if ($("#mid-toast").length === 0) {
                if (toastType === "success") {
                    append(sucHtml);
                } else if (toastType === "fail") {
                    append(failHTml);
                }
            }
        },
        mcMask: function () {
            var maskHtml = "<div id=\"mask\"></div>";
            if ($("#mask").length === 0) {
                $("body").append(maskHtml);
            } else {
                $('#mask').show();
            }
        },

        mcMask2: function () {
            var maskHtml = "<div id=\"mask2\"></div>";
            if ($("#mask2").length === 0) {
                $("body").append(maskHtml);
            } else {
                $('#mask2').show();
            }
        },
        /**
         * 自定义alert弹窗
         * @param alertTitle 弹窗标题 （默认：提示）
         * @param alertTxt 弹窗主题文字内容  （必填）
         * @param actionTxt 弹窗按钮文字  （默认：知道了）
         */
        mcAlert: function (alertTitle, alertTxt, actionTxt, backFn) {
            var alertTitle = (alertTitle === undefined || alertTitle === null || alertTitle === "") ? "提示" : alertTitle;
            var actionTxt = (actionTxt === undefined || actionTxt === null || actionTxt === "") ? "知道了" : actionTxt;
            var alertHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + alertTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + alertTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"single-btn\">" + actionTxt +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(alertHtml);
                $("#popup").show().addClass("pop-animate");
                window.ontouchmove = function (e) {
                    Magiclamp.noScroll(e);
                }
            }
            $("#popup").find(".single-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                if (backFn && typeof backFn == "function") {
                    backFn();
                }
                return false;
            })
        },
        /**
         * 自定义确认弹窗
         * @param confirmTitle 标题 默认：“提示”
         * @param confirmTxt   确认内容，必填
         * @param cancelBtnTxt 取消按钮内容 默认：“”取消
         * @param actionBtnTxt 确认按钮内容 默认“确认”
         * @param cancelFn 点击取消回调
         * @param trueFn 点击确认回调
         */
        mcConfirm: function (confirmTitle, confirmTxt, cancelFn, trueFn) {
            var confirmTitle = (confirmTitle === null || confirmTitle === undefined || confirmTitle === "") ? "提示" : confirmTitle;
            var confirmHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + confirmTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + confirmTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" + "取消" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" + "确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(confirmHtml);
                $("#popup").show().addClass("pop-animate");
                // window.ontouchmove = function (e) {   /*禁止页面滚动*/
                //     Magiclamp.noScroll(e);
                // };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").remove();
                if (cancelFn && typeof cancelFn == "function") {
                    cancelFn();
                }
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").remove();
                if (trueFn && typeof trueFn == "function") {
                    trueFn();
                }
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                return false;
            });
        },
        mcConfirm2: function (confirmTitle, confirmTxt, cancelFn, trueFn) {
            var confirmTitle = (confirmTitle === null || confirmTitle === undefined || confirmTitle === "") ? "提示" : confirmTitle;
            var confirmHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + confirmTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + confirmTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" + "取消" +
                "        </a>" +
                "        <a href=\"javascript:void(0);\" id='mcConfirm_ok'  target=\"\" data-clipboard-action=\"copy\"  data-clipboard-target=\"#live_id\"  class=\"action-btn\">" + "确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(confirmHtml);
                $("#popup").show().addClass("pop-animate");
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                if (cancelFn && typeof cancelFn == "function") {
                    cancelFn();
                }
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                if (trueFn && typeof trueFn == "function") {
                    trueFn();
                }
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return true;
            });
        },

        /**
         * 自定义确认弹窗
         * @param confirmTitle 标题 默认：“提示”
         * @param confirmTxt   确认内容，必填
         * @param cancelBtnTxt 取消按钮内容 默认：“”取消
         * @param actionBtnTxt 确认按钮内容 默认“确认”
         * @param cancelFn 点击取消回调
         * @param trueFn 点击确认回调
         */
        mcConfirm3: function (confirmTitle, confirmTxt, target_url, cancelFn, trueFn) {
            var confirmTitle = (confirmTitle === null || confirmTitle === undefined || confirmTitle === "") ? "提示" : confirmTitle;
            var confirmHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + confirmTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + confirmTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" + "返回" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" + "分享商品" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(confirmHtml);
                $("#popup").show().addClass("pop-animate");
                // window.ontouchmove = function (e) {   /*禁止页面滚动*/
                //     Magiclamp.noScroll(e);
                // };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").remove();
                if (cancelFn && typeof cancelFn == "function") {
                    cancelFn();
                }

                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                if (trueFn && typeof trueFn == "function") {
                    trueFn();
                }
                location.href = target_url;
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        mcConfirm4: function (confirmTitle, confirmTxt, target_url, cancelFn, trueFn) {
            var confirmTitle = (confirmTitle === null || confirmTitle === undefined || confirmTitle === "") ? "提示" : confirmTitle;
            var confirmHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + confirmTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + confirmTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" + "返回" +
                "        </a>" +
                "        <a href=\"" + target_url + "\" target=\"\" class=\"action-btn\">" + "继续前往" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(confirmHtml);
                $("#popup").show().addClass("pop-animate");
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").remove();
                if (cancelFn && typeof cancelFn == "function") {
                    cancelFn();
                }
                return false;
            });

        },
        mcConfirm5: function (confirmTitle, confirmTxt, cancelFn, trueFn) {
            var confirmTitle = (confirmTitle === null || confirmTitle === undefined || confirmTitle === "") ? "提示" : confirmTitle;
            var confirmHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" + confirmTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" + confirmTxt +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" + "拒绝" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\" style='color: red;font-weight: bold;'>" + "好的" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(confirmHtml);
                $("#popup").show().addClass("pop-animate");
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").remove();
                if (cancelFn && typeof cancelFn == "function") {
                    cancelFn();
                }
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                if (trueFn && typeof trueFn == "function") {
                    trueFn();
                }
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });

        },
        /**
         * 带有输入框的弹窗
         * @param promptTitle 弹窗标题，默认：请输入相应信息
         * @param placeholderTxt 弹窗内input的placeholder 默认：请输入相应信息
         * @param cancelFn 取消回调
         * @param trueFn 确认回调
         */
        mcPrompt: function (promptTitle, placeholderTxt, trueFn, value) {
            if(value==undefined){
                value="";
            }
            var promptTitle = (promptTitle === null || promptTitle === undefined || promptTitle === "") ? "请输入相应信息" : promptTitle;
            var placeholderTxt = (placeholderTxt === null || placeholderTxt === undefined || placeholderTxt === "") ? "请输入相应信息" : placeholderTxt;
            var promptHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" +
                promptTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" +
                "        <input type=\"text\" placeholder=\"" + placeholderTxt + "\" value=\"" + value + "\"class='pop-input'>" +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"javascript:return void(0);\" target=\"\" class=\"cancel-btn\">" +
                "            取消" +
                "        </a>" +
                "        <a href=\"javascript:return void(0);\" target=\"\" class=\"action-btn\">" +
                "            确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(promptHtml);
                $("#popup").show().addClass("pop-animate");
                $('#popup').find('.pop-input').focus();
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                var inputVal = $(".pop-input").val();
                if (trueFn && typeof trueFn == "function") {
                    /*传入用户输入的文字*/
                    trueFn(inputVal);
                }
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        /**
         * 带有输入框的弹窗
         * @param promptTitle 弹窗标题，默认：请输入相应信息
         * @param placeholderTxt 弹窗内input的placeholder 默认：请输入相应信息
         * @param cancelFn 取消回调
         * @param trueFn 确认回调
         */
        mcPromptPingLun: function (promptTitle, placeholderTxt, trueFn) {
            var promptTitle = (promptTitle === null || promptTitle === undefined || promptTitle === "") ? "请输入相应信息" : promptTitle;
            var placeholderTxt = (placeholderTxt === null || placeholderTxt === undefined || placeholderTxt === "") ? "请输入相应信息" : placeholderTxt;
            var promptHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" +
                promptTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" +
                "        <textarea type=\"text\" placeholder=\"" + placeholderTxt + "\"class='pop-input' rows='3' style='width: 99%; border:1px solid #000000;'/>" +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" +
                "            取消" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" +
                "            确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(promptHtml);
                $("#popup").show().addClass("pop-animate");
                $('#popup').find('.pop-input').focus();
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                var inputVal = $(".pop-input").val();
                if (trueFn && typeof trueFn == "function") {
                    /*传入用户输入的文字*/
                    trueFn(inputVal);
                }
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        /**
         * 带有输入框的弹窗
         * @param promptTitle 弹窗标题，默认：请输入相应信息
         * @param placeholderTxt 弹窗内input的placeholder 默认：请输入相应信息
         * @param cancelFn 取消回调
         * @param trueFn 确认回调
         */
        mcPrompt2: function (promptTitle, placeholderTxt, trueFn) {
            var promptTitle = (promptTitle === null || promptTitle === undefined || promptTitle === "") ? "请输入相应信息" : promptTitle;
            var placeholderTxt = (placeholderTxt === null || placeholderTxt === undefined || placeholderTxt === "") ? "" : placeholderTxt;
            var promptHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" +
                promptTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" +
                "        <input type=\"text\" value=\"" + placeholderTxt + "\"class='pop-input'>" +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" +
                "            取消" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" +
                "            确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(promptHtml);
                $("#popup").show().addClass("pop-animate");
                $('#popup').find('.pop-input').focus();
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                var inputVal = $(".pop-input").val();
                if (trueFn && typeof trueFn == "function") {
                    /*传入用户输入的文字*/
                    trueFn(inputVal);
                }
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        /**
         * 快递单填写
         * @param promptTitle 弹窗标题，默认：请输入相应信息
         * @param placeholderTxt 弹窗内input的placeholder 默认：请输入相应信息
         * @param cancelFn 取消回调
         * @param trueFn 确认回调
         */
        mcExpressPrompt: function (promptTitle, placeholderTxt, selectData, trueFn) {
            var promptTitle = (promptTitle === null || promptTitle === undefined || promptTitle === "") ? "请输入相应信息" : promptTitle;
            var placeholderTxt = (placeholderTxt === null || placeholderTxt === undefined || placeholderTxt === "") ? "请输入相应信息" : placeholderTxt;
            var o = '';
            for (var i = 0; i < selectData.length; i++) {
                o += '<option value="' + selectData[i].id + '">' + selectData[i].name + '</option>';
            }


            var promptHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">" +
                promptTitle +
                "    </div>" +
                "    <div class=\"pop-main\">" +
                '<select class="pop-select">' +
                o +
                '</select>' +

                "        <input id='e_name' type=\"text\" placeholder=\"" + '快递公司名称(其他快递公司)' + "\"class='pop-input'>" +
                "        <input id='e_no' type=\"text\" placeholder=\"" + placeholderTxt + "\"class='pop-input'>" +
                "    </div>" +

                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" +
                "            取消" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" +
                "            确认" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(promptHtml);
                $("#popup").show().addClass("pop-animate");
                $("#e_name").hide();
                $('#popup').find('.pop-input').focus();
                // window.ontouchmove = function (e) {   /*禁止页面滚动*/
                //     Magiclamp.noScroll(e);
                // };
            }

            $("#popup").find(".pop-select").on("change", function () {
                var e_id = $("#popup").find(".pop-select").val();
                if (e_id != '0') {
                    $("#e_name").hide();
                } else {
                    $("#e_name").show();
                }
            });
            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                var e_id = $("#popup").find(".pop-select").val();
                var e_name = $("#e_name").val();
                var e_no = $("#e_no").val();

                if (trueFn && typeof trueFn == "function") {
                    /*传入用户输入的文字*/
                    trueFn(e_id, e_no, e_name);
                }
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        /**
         * 快递单填写
         * @param promptTitle 弹窗标题，默认：请输入相应信息
         * @param placeholderTxt 弹窗内input的placeholder 默认：请输入相应信息
         * @param cancelFn 取消回调
         * @param trueFn 确认回调
         */
        mcLoginPrompt: function (trueFn) {


            var promptHtml =
                "<div id=\"popup\">" +
                "    <div class=\"pop-title\">登录" +
                "    </div>" +
                "    <div class=\"pop-main\">" +
                "        <input id='e_name' type=\"text\" placeholder=\"" + '用户名' + "\"class='pop-input'>" +
                "        <input id='e_no' type=\"password\" placeholder=\"" + '密码' + "\"class='pop-input'>" +
                "    </div>" +

                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"cancel-btn\">" +
                "            取消" +
                "        </a>" +
                "        <a href=\"\" target=\"\" class=\"action-btn\">" +
                "            登录" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(promptHtml);
                $("#popup").show().addClass("pop-animate");
                $('#popup').find('#e_name').focus();
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }


            $("#popup").find(".cancel-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
            $("#popup").find(".action-btn").on("click", function () {
                var e_name = $("#e_name").val();
                var e_no = $("#e_no").val();

                if (trueFn && typeof trueFn == "function") {
                    /*传入用户输入的文字*/
                    trueFn(e_name, e_no);
                }
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                return false;
            });
        },
        /**
         * 活动弹窗
         * @param actImgUrl  活动图片地址，默认'/img/actimg.jpg'，
         * @param actTitle 活动标题，请勿超过10个字
         * @param actTxt   最多显示两行，css已限制
         * @param fn 点击弹窗按钮后执行的函数
         */
        mcActPop: function (actImgUrl, actTitle, actTxt, fn, backFn) {
            var actImgUrl = (actImgUrl === null || actImgUrl === '' || actImgUrl === undefined) ? '/img/actimg.jpg' : actImgUrl;
            var actPopHtml =
                "<div id=\"popup\" class=\"act-pop\">" +
                "    <div class=\"close-pop\">" +
                "        <i class=\"iconfont icon-shibai\"></i>" +
                "    </div>" +
                "    <div class=\"act-pop-main\">" +
                "<div class='pop-img-wrap'>" +
                "        <img src=\"" + actImgUrl + "\" alt=\"\">" +
                "</div>" +
                "<h1 class='act-title'>" + actTitle + "</h1>" +
                "<p class='act-txt'>" + actTxt + "</p>" +
                "    </div>" +
                "    <div class=\"pop-action\">" +
                "        <a href=\"\" target=\"\" class=\"single-btn\">" +
                "            立即参加" +
                "        </a>" +
                "    </div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(actPopHtml);
                $("#popup").show().addClass("pop-animate");
                window.ontouchmove = function (e) {   /*禁止页面滚动*/
                    Magiclamp.noScroll(e);
                };
            }
            $("#popup").find(".single-btn").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                if (fn && typeof fn == "function") {
                    fn();
                }
                return false;
            });
            $("#popup").find(".close-pop").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                window.ontouchmove = function (e) {  /*解除禁止*/
                    Magiclamp.goScroll(e);
                };
                if (backFn && typeof backFn == "function") {
                    backFn();
                }
            })
        },
        /**
         * 活动弹窗
         * @param actImgUrl  活动图片地址，默认'/img/actimg.jpg'，
         * @param actTitle 活动标题，请勿超过10个字
         * @param actTxt   最多显示两行，css已限制
         * @param fn 点击弹窗按钮后执行的函数
         */
        mcImgPop: function (actImgUrl, actTitle, actTxt, fn, backFn) {
            var actImgUrl = (actImgUrl === null || actImgUrl === '' || actImgUrl === undefined) ? '/img/actimg.jpg' : actImgUrl;
            var actPopHtml =
                "<div id=\"popup\" class=\"act-pop\">" +
                "    <div class=\"act-pop-main2\">" +
                "<div class='pop-img-wrap'>" +
                "        <img src=\"" + actImgUrl + "\" alt=\"\">" +
                "</div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask();
                $("body").append(actPopHtml);
                $("#popup").show().addClass("pop-animate");
                // window.ontouchmove = function (e) {   /*禁止页面滚动*/
                //     Magiclamp.noScroll(e);
                // };
            }
            $("#popup").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                if (fn && typeof fn == "function") {
                    fn();
                }
                return false;
            });
            $("#popup").find(".close-pop").on("click", function () {
                $("#popup").remove();
                $("#mask").hide();
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                if (backFn && typeof backFn == "function") {
                    backFn();
                }
            })
        },
        mcImgPop2: function (actImgUrl, actTitle, actTxt, fn, backFn) {
            var actImgUrl = (actImgUrl === null || actImgUrl === '' || actImgUrl === undefined) ? '/img/actimg.jpg' : actImgUrl;
            var actPopHtml =
                "<div id=\"popup\" class=\"act-pop\">" +
                "    <div class=\"act-pop-main2\">" +
                "<div class='pop-img-wrap'>" +
                "        <img src=\"" + actImgUrl + "\" alt=\"\">" +
                "</div>" +
                "</div>";
            if ($("#popup").length === 0) {
                this.mcMask2();
                $("body").append(actPopHtml);
                $("#popup").show().addClass("pop-animate");
                // window.ontouchmove = function (e) {   /*禁止页面滚动*/
                //     Magiclamp.noScroll(e);
                // };
            }
            $("#popup").on("click", function () {
                $("#popup").remove();
                $("#mask2").hide();
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                if (fn && typeof fn == "function") {
                    fn();
                }
                return false;
            });
            $("#popup").find(".close-pop").on("click", function () {
                $("#popup").remove();
                $("#mask2").hide();
                // window.ontouchmove = function (e) {  /*解除禁止*/
                //     Magiclamp.goScroll(e);
                // };
                if (backFn && typeof backFn == "function") {
                    backFn();
                }
            })
        },
        /**
         * 屏幕中间loading
         * @param loadingTxt loading提示文字 默认’加载中...‘
         */
        midLoadingShow: function (loadingTxt) {
            var loadingTxt = (loadingTxt === '' || loadingTxt === null || loadingTxt === undefined) ? "加载中..." : loadingTxt;
            var loadingHtml =
                "<div id=\"loading\">" +
                "    <div  class=\"loading\">" +
                "        <span></span>" +
                "        <span></span>" +
                "        <span></span>" +
                "        <span></span>" +
                "        <span></span>" +
                "    </div>" +
                "<p>" + loadingTxt + "</p>" +
                "</div>";
            if ($("#loading").length === 0) {
                $("body").append(loadingHtml);
            } else {
                $('#loading').hide();
            }
        },
        /**
         * 隐藏loading
         */
        midLoadingHide: function () {
            $("#loading").remove();
        },
        /**
         * document.referrer判断是否显示header返回按钮
         */
        ckReffer: function () {
            return document.referrer;
        },
        /**
         * 默认将返回按钮通过m-hide属性隐藏
         * 如果document.referrer不为空，显示返回按钮
         **/
        toggleBack: function () {
            if (this.ckReffer() !== "") {
                $(".back-btn").show();
            }
        },
        /**
         * 详情页面猜你喜欢ul宽度计算
         */
        calUlWidth: function () {
            var likeUl = $(".like-goods > ul");
            var likeGoods = $(".like-goods li");
            var doWidthCal = function () {
                var ulWidth = 0;
                likeGoods.each(function () {
                    ulWidth += $(this).width();
                });
                likeUl.width(ulWidth);
            };
            if ($(".like-goods").length < 1) {
                return false;
            } else {
                doWidthCal()
            }
            //窗口大小变化时，重新计算（如横屏等用户事件）
            $(window).bind("resize", function () {
                doWidthCal();
            });
        },
        /**
         * 调整数量控件方法
         */
        quantityCtrl: function (plusFn, minusFn) {
            var _this = this;
            var $plusBtn = $(".count-plus");
            var $minusBtn = $(".count-minus");
            $plusBtn.on("click", function () {
                var sum = $(this).prev(".count-sum");
                var sumNum = Number(sum.html());
                var max = Number($(this).data("max"));
                var maxMsg = $(this).data("msg");
                if (sumNum >= max) {
                    _this.mcAlert("", maxMsg, "");
                    return false;
                }
                sumNum += 1;
                sum.html(sumNum);
                if (plusFn && typeof plusFn == "function") {
                    plusFn();
                }
            });
            $minusBtn.on("click", function () {
                var sum = $(this).next(".count-sum");
                var sumNum = Number(sum.html());
                var min = Number($(this).data("min"));
                var minusMsg = $(this).data("msg");
                if (sumNum > min) {
                    sumNum -= 1;
                    sum.html(sumNum);
                    if (minusFn && typeof minusFn == "function") {
                        minusFn();
                    }
                } else if (sumNum === 1) {
                    _this.mcAlert("", minusMsg, "");
                }
            });
        },
        /**
         * 购物车全选
         * @param chkAllId string 全选按钮id，默认"#chk-all"
         * @param chkBoxWrap string 需要全选的checkbox所在的父容器id 默认"#cart-list"
         */
        cartChkAll: function (chkAllId, chkBoxWrap) {
            var $chkAll = chkAllId === undefined ? $("#chk-all") : $(chkAllId);
            var $chkBoxWrap = chkBoxWrap === undefined ? $("#cart-list") : $(chkBoxWrap);
            var $chkBox = $chkBoxWrap.find("input");
            if ($chkBoxWrap.find("input:checked").length == $chkBox.length) {
                $chkAll.prop("checked", true);
            } else {
                $chkAll.prop("checked", false);
            }
            $chkAll.click(function () {
                var _this = this;
                $chkBox.each(function () {
                    this.checked = _this.checked;
                });
            });
            $chkBox.bind("click", function () {
                if ($chkBoxWrap.find("input:checked").length == $chkBox.length) {
                    $chkAll.prop("checked", true);
                } else {
                    $chkAll.prop("checked", false);
                }
            })
        },
        /**
         *jQuery Ajax方法简易封装
         * @param url string 发送请求的地址
         * @param type string 默认GET
         * @param data 数据  默认data：new Date().getTime()
         * @param successFn 成功回调函数
         * @param errorFn 失败回调
         * @param async  是否异步,默认 true
         **/
        mcAjax: function (url, type, data, successFn, errorFn, async) {
            var type = (type == null || type == "" || typeof (type) == "undefined") ? "GET" : type;
            var async = (async === null || async === "" || typeof (async) === "undefined") ? true : async;
            var data = (data == null || data == "" || typeof (data) == "undefined") ? {"date": new Date().getTime()} : data;
            $.ajax({
                url: url,
                type: type,
                data: data,
                dataType: "json",
                async: async,
                success: function (d) {
                    successFn(d);
                },
                error: function (e) {
                    errorFn(e);
                }
            });
        },
        /**
         *上滑tab底部滑出，下滑tab底部滑入
         * @param upFn 上滑执行函数
         * @param downFn 下滑执行函数
         */
        swipeHideTab: function (upFn, downFn) {
            var startX = 0, startY = 0;

            function touchStart(evt) {
                try {
                    var touch = evt.touches[0], //获取第一个触点
                        x = Number(touch.pageX), //页面触点X坐标
                        y = Number(touch.pageY); //页面触点Y坐标
                    //记录触点初始位置
                    startX = x;
                    startY = y;
                } catch (e) {
                    console.log(e.message)
                }
            }

            function touchMove(evt) {
                try {
                    var touch = evt.touches[0], //获取第一个触点
                        x = Number(touch.pageX), //页面触点X坐标
                        y = Number(touch.pageY); //页面触点Y坐标
                    //判断滑动方向
                    if (y - startY > 0) {
                        // console.log("下滑了！");
                        downFn();
                    } else {
                        upFn();
                        // console.log("上滑了！");
                    }
                } catch (e) {
                    // console.log(e.message)
                }
            }

            function touchEnd(evt) {
                try {
                    var touch = evt.touches[0], //获取第一个触点
                        x = Number(touch.pageX), //页面触点X坐标
                        y = Number(touch.pageY); //页面触点Y坐标
                    //判断滑动方向
                    if (y - startY > 0) {
                        // console.log("下滑了！");
                        downFn();
                    } else {
                        // console.log("上滑了！");
                        upFn();
                    }
                } catch (e) {
                    // console.log(e.message)
                }
            }

            //绑定事件
            document.addEventListener("touchstart", touchStart, false);
            document.addEventListener("touchmove", touchMove, false);
            document.addEventListener("touchend", touchEnd, false);
        },
        /**
         *tab-bar根据参数添加class
         * @param string 共有4个（"self_service","discovery","替你付款，待定","user_center"）
         */
        tabAddCls: function (string) {
            $("#tab-bar").find("." + string).addClass("on")
        },
        /**
         * 获取短信验证码 倒计时开始，倒计时结束后重新获取
         * @param fn 点击获取验证码后的附带函数
         */
        getMsgCode: function (fn) {
            var codeBtn = $("#code-btn");
            var g = true;
            var timer = null;
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*手机号输入框*/
            codeBtn.on("click", function () {
                var phoneInput = $(this).prev('input[name="u_mobile"]');
                var phoneVal = phoneInput.val();
                if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                    _this.midToast("fail", "手机号码格式错误");
                    return false;
                }
                if (g === true) {
                    var time = 60;
                    _this.mcToast("验证码已发送", "4rem");
                    codeBtn.html(time + "s" + "后重新获取");
                    g = false;
                    $(this).addClass("disable");
                    timer = setInterval(function () {
                        if (time > 1) {
                            time--;
                            codeBtn.html(time + "s" + "后重新获取");
                        } else if (time == 1) {
                            clearInterval(timer);
                            codeBtn.removeClass("disable").html("重发验证码");
                            g = true;
                        }
                    }, 1000);
                    if (fn && typeof fn === 'function') {
                        fn();
                    }
                }
            })
        },
        /**
         * 列表加载更多 loading
         * @param elem 加载更多按钮 默认 $(".get-more")
         * */
        listLoad: function (elem) {
            var elem = (elem === null || elem === undefined || elem === '') ? $(".get-more") : elem;
            var loadingHtml =
                "<span class=\"loading-sk\"></span> 加载中...";
            elem.html(loadingHtml).css({
                color: "#999",
                pointerEvents: "none"
            });
        },
        /**
         * 加载更多loading后执行函数
         * @param elem  加载更多按钮 默认 $(".get-more")
         * @param noticeTxt  按钮提示文字, 默认"加载更多"
         * @param btnCss  按钮是否可点击,可点击:auto,不可点击none; 默认为auto,可点击
         */
        listLoadGet: function (elem, noticeTxt, btnCss) {
            var elem = (elem === null || elem === undefined || elem === '') ? $(".get-more") : elem;
            var noticeTxt = (noticeTxt === null || noticeTxt === undefined || noticeTxt === '') ? "加载更多" : noticeTxt;
            var btnCss = (btnCss === null || btnCss === undefined || btnCss === '') ? "auto" : btnCss;
            elem.html(noticeTxt).css({
                color: "#666",
                pointerEvents: btnCss
            });
        },
        /**
         * 判断是否微信打开,判断对应支付方式
         * @returns {boolean}
         */
        inWeixin: function () {
            var ua = navigator.userAgent.toLowerCase();
            return ua.match(/MicroMessenger/i) == "micromessenger";
        },
        /**
         * 开门进度条
         * @param speed 默认是600ms, 走完100%进度条是60000ms,一分钟
         * @param ajaxFn 向服务器申请数据,返回true/false;
         * @param fn  根据ajaxFn返回值,判断是否执行
         * @param endFn 走完100%后执行的函数
         */
        mcProgress: function (speed, ajaxFn, fn, endFn) {
            var goSpeed = (speed === '' || speed === null || speed === undefined) ? 600 : speed;
            var proBar = $('.prss-wrap').find('.progress');
            var i = 0;
            var timer = null;
            timer = setInterval(function () {
                i += 1;
                proBar.width(i + '%');
                if (i === 100) {
                    clearInterval(timer);
                    if (endFn && typeof endFn === "function") {
                        endFn();
                    }
                }
            }, goSpeed);
            if (ajaxFn && typeof ajaxFn === "function") {
                var ajaxBoolen = ajaxFn();
            }
            if (ajaxBoolen) {
                if (fn && typeof fn === "function") {
                    fn();
                    return false;
                }
            }
        },
        /**
         * 根据data-src先确定图片容器尺寸,适应各种尺寸
         */
        imgSrc: function () {
            //横竖屏时重新计算图片高度
            var iWidth = ($(window).width()) / 3;
            var j = 43 / 32;
            var iHeight = iWidth / j;
            var iWidthTwo = ($(window).width()) / 2;
            var iHeightTwo = iWidthTwo / j;
            $('.sd-goods .img-wrap, .dn-goods .img-wrap').css({
                'height': iHeight,
                'overflow': 'hidden'
            });
            $('.i-g-list .img-wrap').css({
                'height': iHeightTwo,
                'overflow': 'hidden'
            });
            /* *在用户变化屏幕显示方向的时候调用*/
            $(window).on('resize', function () {
                //横竖屏时重新计算图片高度
                var iWidth = ($(window).width()) / 3;
                var j = 43 / 32;
                var iHeight = iWidth / j;
                var iWidthTwo = ($(window).width()) / 2;
                var iHeightTwo = iWidthTwo / j;
                $('.sd-goods .img-wrap, .dn-goods .img-wrap').css({
                    'height': iHeight,
                    'overflow': 'hidden'
                });
                $('.i-g-list .img-wrap').css({
                    'height': iHeightTwo,
                    'overflow': 'hidden'
                });
            });
            $('.img-wrap img, .img-box img').each(function () {
                if ($(this).data("src")) {
                    $(this).attr('src', $(this).data('src'));
                }
            });
        },
        /**
         * 图片错误后处理
         */
        imgError: function () {
            var imgs = document.getElementsByTagName('img');
            for (var i = 0, len = imgs.length; i < len; i++) {
                imgs[i].onerror = function () {
                    this.setAttribute("src", "/img/gray.gif");
                }
            }
        },
        /**
         * 账号密码登录表单验证,请严格遵守验证中的表单name命名规则
         * @param form 需要验证的form表单
         * @returns {boolean}
         */
        accLoginvalid: function (form) {
            var form = form;
            var $inputs = form.find("input");
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*手机号输入框*/
            var phoneInput = form.find('input[name="u_mobile"]');
            var phoneVal = phoneInput.val();
            /*密码输入框*/
            var passInput = form.find('input[name="u_pass"]');
            var passVal = passInput.val();
            var pass = true;
            /*输入框为空验证*/
            if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                _this.midToast("fail", "手机号码格式错误");
                pass = false;
            }
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写信息");
                    pass = false;
                }
            });
            if (passVal.length < 6 || passVal.length > 32) {
                _this.midToast("fail", "请输入6-32位密码");
                pass = false;
            }
            return pass;
        },
        /**
         * 验证码登录表单验证 ,请严格遵守验证中的表单name命名规则
         *  @param form 需要验证的form表单
         * @returns {boolean}
         */
        codeLoginValid: function (form) {
            var form = form;
            var $inputs = form.find("input");
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*验证码验证*/
            var regcode = /(^[0-9]{6}$)/;
            /*手机号输入框*/
            var phoneInput = form.find('input[name="u_mobile"]');
            var phoneVal = phoneInput.val();
            /*验证码输入*/
            var codeInput = form.find('input[name="u_code"]');
            var codeVal = codeInput.val();
            var pass = true;
            /*输入框为空验证*/
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写信息");
                    pass = false;
                }
            });
            if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                _this.midToast("fail", "手机号码格式错误");
                pass = false;
            }
            if (codeVal.length !== 6 || !(regcode.test(codeVal))) {
                _this.midToast("fail", "验证码格式错误");
                pass = false;
            }
            return pass;
        },
        /**
         *注册表单验证,请严格遵守验证中的表单name命名规则
         * @param form 需要验证的form表单
         * @returns {boolean}
         */
        regValid: function (form) {
            var form = form;
            var $inputs = form.find("input");
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*手机号输入框*/
            var phoneInput = form.find('input[name="u_mobile"]');
            var phoneVal = phoneInput.val();
            /*验证码输入*/
            var codeInput = form.find('input[name="u_code"]');
            var codeVal = codeInput.val();
            /*密码输入框*/
            var passInput = form.find('input[name="u_pass"]');

            var passInputConfirm = form.find('input[name="u_pass_r"]');
            var passVal = passInput.val();
            var passcofirmval = passInputConfirm.val();
            var pass = true;


            /*输入框为空验证*/
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写");
                    pass = false;
                }
            });
            if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                _this.midToast("fail", "手机号码格式错误");
                pass = false;
            }
            if (codeVal.length !== 6) {
                _this.midToast("fail", "验证码格式错误");
                pass = false;
            }
            if (passVal.length < 6 || passVal.length > 32) {
                _this.midToast("fail", "请设置6-32位密码");
                pass = false;
            }


            if (passVal !== passcofirmval) {
                _this.midToast("fail", "输入密码不一致");
                pass = false;
            }
            return pass;
        },
        /**
         *修改密码表单验证,请严格遵守验证中的表单name命名规则
         *  @param form 需要验证的form表单
         * @returns {boolean}
         */
        chgPassValid: function (form) {
            var form = form;
            var $inputs = form.find("input");
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*验证码验证*/
            var regcode = /(^[0-9]{6}$)/;
            /*手机号输入框*/
            var phoneInput = form.find('input[name="u_mobile"]');
            var phoneVal = phoneInput.val();
            /*验证码输入*/
            var codeInput = form.find('input[name="u_code"]');
            var codeVal = codeInput.val();
            /*密码输入框*/
            var passInput = form.find('input[name="u_pass"]');
            var passVal = passInput.val();
            /*确认密码输入框*/
            var passConfirmInput = form.find('input[name="u_pass_confirm"]');
            var passConfirmVal = passConfirmInput.val();
            var pass = true;
            /*输入框为空验证*/
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写信息");
                    pass = false;
                }
            });
            if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                _this.midToast("fail", "手机号码格式错误");
                pass = false;
            }
            if (codeVal.length !== 6 || !(regcode.test(codeVal))) {
                _this.midToast("fail", "验证码格式错误");
                pass = false;
            }
            if (passVal.length < 6 || passVal.length > 32 || passConfirmVal.length < 6 || passConfirmVal.length > 32) {
                _this.midToast("fail", "请设置6-32位密码");
                pass = false;
            }
            if (passConfirmVal !== passVal) {
                _this.midToast("fail", "确认新密码有误");
                pass = false;
            }
            return pass;
        },
        /**
         * 加盟表单验证
         * @param form 需要验证的表单
         */
        joinUSValid: function (form) {
            var form = form;
            var $inputs = form.find("input, textarea");
            var _this = this;
            /*手机号验证*/
            var reg = /^1(3|4|5|7|8)\d{9}$/;
            /*手机号输入框*/
            var phoneInput = form.find('input[name="u_mobile"]');
            var phoneVal = phoneInput.val();
            /*验证码输入*/
            var nameInput = form.find('input[name="u_name"]');
            var nameVal = nameInput.val();
            /*密码输入框*/
            var tradeInput = form.find('input[name="u-trade"]');
            var tradeVal = tradeInput.val();
            var pass = true;
            /*输入框为空验证*/
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写信息");
                    pass = false;
                }
            });
            if (phoneVal.length !== 11 || !(reg.test(phoneVal))) {
                _this.midToast("fail", "手机号码格式错误");
                pass = false;
            }
            return pass;
        },
        /**
         * 验证码登录后设置密码表单验证
         * @param form 需要验证的表单
         * @returns {boolean}
         */
        loginSetVaild: function (form) {
            var form = form;
            var $inputs = form.find("input");
            var _this = this;
            /*密码输入框*/
            var passInput = form.find('input[name="u_pass"]');
            var passVal = passInput.val();
            /*确认密码输入框*/
            var passConfirmInput = form.find('input[name="u_pass_confirm"]');
            var passConfirmVal = passConfirmInput.val();
            var pass = true;
            /*输入框为空验证*/
            $inputs.each(function () {
                if ($(this).val() === "") {
                    _this.midToast("fail", "请完整填写信息");
                    pass = false;
                }
            });
            if (passVal.length < 6 || passVal.length > 32 || passConfirmVal.length < 6 || passConfirmVal.length > 32) {
                _this.midToast("fail", "请设置6-32位密码");
                pass = false;
            }
            if (passConfirmVal !== passVal) {
                _this.midToast("fail", "确认新密码有误");
                pass = false;
            }
            return pass;
        },
        /**
         * 商品详情页面无货遮罩
         * @param errorNum 错误数字 3或4 3代表无货，4代表设备掉线
         * @param delTxt 是否删除联系前台电话的p标签
         */
        hasError: function (errorNum, telNum, delTxt) {
            var delTxt = (delTxt === null || delTxt === undefined || delTxt === '') ? false : delTxt;
            var imgBox = $('.img-box');
            var goodsMask =
                "<div class=\"has-error\">" +
                "            <img src=\"/img/haserr-" + errorNum + ".png\" alt=\"\">" +
                "            <p class=\"mask-error-txt\">如有疑问请联系：<a href=\"tel:" + telNum + "\">" + telNum + "</a></p>" +
                "        </div>";
            if (!$('.has-error').length) {
                imgBox.append(goodsMask);
            }
            if (delTxt) {
                $('.mask-error-txt').remove();
            }
            var changeSome = function () {
                $('#addcart').css({
                    background: "#b3b3b3",
                    borderTop: "#b3b3b3",
                    pointerEvents: "none"
                });
                $('#buy_now').css({
                    background: "#999",
                    borderTop: "#999",
                    pointerEvents: "none"
                });
                $('.count-plus , .count-minus').css({
                    pointerEvents: "none"
                });
            };
            changeSome();
            $(window).on('resize', function () {
                changeSome();
            });
        },
        /**
         * 神灯商品无货,柜门错误等提示用户前往店内此商品详情购买
         * @param url 店内此商品的链接地址
         */
        noticeShow: function (url) {
            $('#naked-notice').addClass('notice-show');
            $('#naked-notice').prop('href', url)
        },
        /**
         * 设置cookie
         * @param name key
         * @param value value
         */
        setCookie: function (name, value) {
            document.cookie = name + "=" + escape(value);
        },
        /**
         * 获取cookie
         * @param name cookie name
         * @returns {*}
         */
        getCookie: function (name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            arr = document.cookie.match(reg);
            if (arr) {
                return (arr[2]);
            } else
                return null;
        },
        /**
         * 金额转换，分--->元
         * @param sum  要转换的金额
         * @returns {string} 返回数字
         */
        amountInto: function (sum) {
            return (Number(sum) / 100).toFixed(2);
        }
    };
    window.Magiclamp = Magiclamp;
})(jQuery);
/*调用*/
$(function () {
    //判断当前页面是否显示返回按钮
    Magiclamp.toggleBack();
    //计算详情页面猜你喜欢ul宽度,达到滑动效果
    Magiclamp.calUlWidth();
    //购物车全选
    Magiclamp.cartChkAll();
    Magiclamp.imgSrc();
    Magiclamp.imgError();
    // Magiclamp.hasError('此柜门无关联商品', "13512080888", false);
});
